/*
   @Copyright:LintCode
   @Author:   tjyemail
   @Problem:  http://www.lintcode.com/problem/powx-n
   @Language: C++
   @Datetime: 16-02-09 08:22
   */

class Solution {
public:
	/**
	 * @param x the base number
	 * @param n the power number
	 * @return the result
	 */
	double myPow(double x, int n) {
		// Write your code here
		double ans=1;
		if (n<0) return 1/myPow(x,-n);
		for(ans=1; n; x*=x, n>>=1)
			ans *= (n&1 ? x : 1);
		return ans;
	}
};
